package com.example.mobiledatapackage.response.uniformat;

import lombok.Data;

/**
 * 统一返回格式
 * @param <T> 有效的返回数据类型
 */
@Data
public class ResultData<T> {
    /** 结果状态 ,具体状态码参见ResultData.java*/
    private int code;
    private String message;
    private T result;
    private String type;


    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCode.SUCCESS.getCode());
        resultData.setMessage(ReturnCode.SUCCESS.getMessage());
        resultData.setResult(data);
        resultData.setType("success");
        return resultData;
    }

    public static <T> ResultData<T> fail(int code, String message) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        resultData.setType("fail");
        return resultData;
    }

}